<?php


namespace app\common\validate;


use think\Validate;


// Admin用户验证器类
class AdminValidate extends Validate
{
    // 验证规则
    protected $rule = [
        'username|管理员账户' => 'require|min:2|max:32',
        'password|密码' => 'require|min:6|max:12',
        're_password|确认密码' => 'require|min:6|max:12|confirm:password',
        'nickname|昵称' => 'require|min:2|max:12|unique:admin',
        'email|邮箱' => 'require|email|unique:admin',
        'code|验证码' => 'require',
    ];


    // 登录验证场景
    public function sceneLogin()
    {
        return $this->only(['username', 'password']);
    }

    // 注册验证场景
    public function sceneRegister(){
        return $this->only(['username', 'password', 're_password', 'nickname', 'email'])
            ->append('username', 'unique:admin')
            ->append('nickname', 'unique:admin');
    }

    // 重置密码验证场景
    public function sceneReset()
    {
        return $this->only(['code']);
    }

    // 添加管理员场景验证
    public function sceneAdd()
    {
        return $this->only(['username', 'password', 'nickname', 'email'])
            ->append('username', 'unique:admin')
            ->append('nickname', 'unique:admin');
    }


    // 编辑管理员场景验证
    public function sceneEdit()
    {
        return $this->only(['username', 'nickname', 'email'])
            ->append('username', 'unique:admin')
            ->append('nickname', 'unique:admin');
    }

}